package com.csu.express.controller.app;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.csu.common.exception.WebException;
import com.csu.common.vo.ResultVo;
import com.csu.express.pojo.OrderCommentsPojo;
import com.csu.express.service.OrderCommentsService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * @项目名称：express
 * @类名称：OrderCommentsController
 * @类描述：订单评价类（包括评价、查看评价信息）
 * @创建人：阳凯
 * @创建时间：2017年10月28日 下午7:06:52
 * @company:姚速运
 */
@Controller
@RequestMapping("/orderComments")
@Api(value = "orderComments", description = "订单评价接口")
public class OrderCommentsController
{

    @Autowired
    private OrderCommentsService orderCommentsService;

    @ResponseBody
    @ApiOperation(value = "添加订单评价", notes = "用户添加订单评价记录")
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = { "application/json; charset=utf-8" })
    public ResultVo<Integer> addOrderComments(HttpServletRequest request, @RequestBody OrderCommentsPojo orderCommentsPojo) throws WebException
    {
        ResultVo<Integer> resultVo = new ResultVo<>();
        int result = orderCommentsService.addOrderComments(orderCommentsPojo);
        resultVo.setData(result);
        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "获取订单评价记录", notes = "用户获取评价记录")
    @RequestMapping(value = "/list/{cellPhone}", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" })
    public ResultVo<List<OrderCommentsPojo>> getOrderCommentsByCellPhone(HttpServletRequest request,
            @ApiParam(value = "电话号码") @PathVariable(value = "cellPhone") String cellPhone) throws WebException
    {
        ResultVo<List<OrderCommentsPojo>> resultVo = new ResultVo<>();
        List<OrderCommentsPojo> orderCommentsPojos = orderCommentsService.getCommentListByCellPhone(cellPhone);
        resultVo.setData(orderCommentsPojos);
        return resultVo;
    }

    @ResponseBody
    @ApiOperation(value = "获取订单评价记录", notes = "用户获取评价记录")
    @RequestMapping(value = "/getByOrderId/{orderId}", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" })
    public ResultVo<OrderCommentsPojo> getOrderCommentsByOrderId(HttpServletRequest request,
            @ApiParam(value = "订单流水号") @PathVariable(value = "orderId") String orderId) throws WebException
    {
        ResultVo<OrderCommentsPojo> resultVo = new ResultVo<>();
        OrderCommentsPojo orderCommentsPojo = orderCommentsService.getCommentsByOrderId(orderId);
        resultVo.setData(orderCommentsPojo);
        return resultVo;
    }
}
